package com.wpw.dream.queue;

import java.util.concurrent.ArrayBlockingQueue;

public class BlockingQueueTest {

	public  void dd() throws InterruptedException {
		
		final ArrayBlockingQueue<Integer> abq = new ArrayBlockingQueue<>(100, true);
		
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				try {
					Integer take = abq.take();
					/*if (Thread.currentThread().getName().equals("0")) {
						Thread.sleep(5000);
					}*/
					System.out.println("线程"+Thread.currentThread().getName() + ":" + take);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
			}
		}, "0").start();
		
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				try {
					Integer take = abq.take();
					System.out.println("线程"+Thread.currentThread().getName() + ":" + take);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
			}
		}, "1").start();
		
		//Thread.sleep(2000);
		abq.put(1);
		abq.put(2);
		abq.put(3);
		
	}
}
